package org.example.struct.array;

/**
 * @author liyishan
 * @date 2023/8/24 10:30
 * @apiNote
 */

public class Test01588ContainsPattern {
    public static void main(String[] args) {
        int[] arr = {1, 4, 2, 5, 3};
        int count = test(arr);
        System.out.println(count);
    }

    public static int test(int[] arr) {
        int sum = 0;
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            for (int j = 1; i + j <= n; j+=2) {
                int end = i + j - 1;
                for (int k = i; k <= end; k++) {
                    sum += arr[k];
                }
            }
        }
        return sum;
    }

    public static int test1(int[] arr){
        int n = arr.length;
        int[] prefixSum = new int[n+1];
        for(int i = 0;i<n;i++){
            prefixSum[i+1] = prefixSum[i] + arr[i];
        }
        int sum = 0;
        for(int i = 0;i<n;i++){
            for(int j = 1;i+j<=n;j+=2){
                int end = i+j-1;
                sum += prefixSum[end+1] - prefixSum[i];
            }
        }
        return sum;
    }

}
